/*
 * @Autor: dingxiaolin
 * @Date: 2020-06-16 22:39:09
 * @LastEditors: dingxiaolin
 * @LastEditTime: 2020-06-17 23:15:22
 */ 
import {CHANGE_INPUT,ADD_LIST,DELETE_ITEM,GET_LIST} from './actionType'
const initstate ={
    value:'小吃',
    list:[]
}
export default(state=initstate,action)=>{
    console.log(state,action);
    // reducer 只能接受state，不能改变state
    // reducer 必须是纯函数，内部不可异步接口调用
    switch (action.type) {
        case CHANGE_INPUT:
            return {
                ...state,
                value:action.value
            }
        case ADD_LIST:
            return {
                ...state,
                list:[...state.list,{address:action.value}]
            }
        case DELETE_ITEM:
            state.list.splice(action.index,1) //删除某个位置的数据
            return {
                ...state
            }
        case GET_LIST:
            state.list=[...action.value]
            return {
                ...state
            }
        default:
            return state
    }
    // if(action.type==='changeInput'){
    //     let newState= JSON.parse(JSON.stringify(state))
    //     newState.value=action.value;
    //     return newState
    // }
    // return state
}